#include "../HttpFixedResponse.h"
#include "../HttpResponse.h"
#include "../Route.h"
#include "../ServerStruct.h"
#include "../common/YXConstant.h"
#include "../common/YXLog.h"
#include "../common/YXResult.h"
#include "../local/buckets/BucketsMeta.h"

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "../service/BucketsService.h"


/**
 * 创建桶
 */
static YXResult* postBucketHandler(Request *request, Response *response) {
    char* bucketName = request->body;
    return postBucket(bucketName);
}

/**
 * 获取桶列表
 */
static YXResult *getBucketListHandler(Request *request, Response *response) { return getBuckets(); }

/**
 * 获取桶总结
 */
static YXResult* getBucketSummaryHandler(Request *request, Response *response) {
    char** pathVariables = request->parsed_data;
    return getBucketSummary(pathVariables[0]);
}


static void putRenameBucketHandler(Request *request, Response *response) {}
static void deleteBucketHandler(Request *request, Response *response) {}

__attribute__((constructor)) void bucketsControllerInit() {
    addRoute("GET", "/op/buckets", NULL, getBucketListHandler);
    addRoute("GET", "/op/buckets/summary/{name}", PATH_VARIABLE_ANNOTATION, getBucketSummaryHandler);
    addRoute("POST", "/op/buckets", NULL, postBucketHandler);
    addRoute("PUT", "/op/buckets", NULL, putRenameBucketHandler);
    addRoute("DELETE", "/op/buckets", NULL, deleteBucketHandler);
}
